/**
 * 
 */
package com.xpec.c4.game.utility;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * 將字串寫入文字檔的物件
 * 
 * @author TW15010
 */
public class TextFileWriter {
	private File file;
	private BufferedWriter writer;

	/**
	 * 建立檔案，檔案已經存在會被覆蓋
	 * 
	 * @param fileName
	 *            檔名
	 */
	public void createFile(String fileName) {
		file = new File(fileName);
		try {
			writer = new BufferedWriter(new FileWriter(file));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 寫入指定的字串
	 * 
	 * @param text
	 *            字串
	 */
	public void writeText(String text) {
		try {
			writer.write(text);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 關閉檔案
	 */
	public void closeFile() {
		try {
			writer.close();
			file = null;
			writer = null;
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
